package com.cnswhy.cloud.server.app.controller.notify;

import com.cnswhy.cloud.common.core.exception.BizException;
import com.cnswhy.cloud.common.core.mybatis.conditions.Wraps;
import com.cnswhy.cloud.common.redis.service.RedisService;
import com.cnswhy.cloud.server.app.controller.BaseController;
import com.cnswhy.cloud.server.core.entity.CustomerWithdrawalRecord;
import com.cnswhy.cloud.server.core.service.CustomerWithdrawalRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * T
 */
@Controller
@RequestMapping("/HcPayNotify")
@Slf4j
public class HcPayNotify extends BaseController {


    @Autowired
    private RedisService redisService;

    @Autowired
    private CustomerWithdrawalRecordService customerWithdrawalRecordService;


    @SuppressWarnings("rawtypes")
    @PostMapping("/hcDfCallback")
    public void hcDfCallback(String orderId) {
        try {
            CustomerWithdrawalRecord customerWithdrawalRecord = customerWithdrawalRecordService.getOne(Wraps.<CustomerWithdrawalRecord>lbQ().eq(CustomerWithdrawalRecord::getChannelOrderId, orderId));

            //messageService.send(MQConstant.PAYBANK_QUERY_QUEUE, JSON.toJSONString(paybankOrder));
        } catch (BizException e) {
        }
    }

    /**
     * 描述：防止回调重复，校验redis中是否已经存在此订单
     * 作者：张润泽
     * 时间：2019年3月19日 上午10:48:42
     *
     * @param orderNo
     * @return true 不存在此订单  false 已存在此订单
     */
    private boolean validateOrderNo(String orderNo) {
        String order = (String) redisService.get(orderNo);
        if (StringUtils.isBlank(order)) {
            // 将订单号放入redis中60分钟
            redisService.set(orderNo, "60");
            redisService.expire(orderNo, 600L);
            return true;
        }
        return false;
    }
}
